#include "end.h"
#include "ui_end.h"

End::End(QWidget *parent, int time, int death) :
    QDialog(parent),
    ui(new Ui::End)
{
    ui->setupUi(this);

    this->setFixedSize(800,600);
    this->ui->background->setGeometry(0,0,800,600);
    QPixmap *bkground = new QPixmap("Images\\OpeningScreen.png");
    this->ui->background->setPixmap(*bkground);
    this->ui->background->show();

    int score = time + death*5;
    QString *str = new QString;
    *str = "Time: " + QString::number(time) + "\n";
    *str += "Deaths: " + QString::number(death) + "\n\n";
    *str += "Score: " + QString::number(score) + "\n";
    if(score < 30)
        *str += "Rank: Cheater!" ;
    else if(score < 100)
        *str += "Rank: S" ;
    else if(score < 120)
        *str += "Rank: A" ;
    else if(score < 140)
        *str += "Rank: B" ;
    else if(score < 160)
        *str += "Rank: C" ;
    else
        *str += "Rank: D" ;

    QFont font("arial", 22);
    QString style = " color: white; ";

    ui->score->setText(*str);
    ui->score->setFont(font);
    ui->score->setStyleSheet(style);
}

End::~End()
{
    delete ui;
}

void End::on_pushButton_clicked()
{
    dynamic_cast<MainMenu*>(this->parent()->parent())->show();
    this->parent()->deleteLater();
    this->deleteLater();
}
